﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace BinAnalysisHelp
{
  public  class SettingPUCT
    {

        public static bool IsPrint = false;
        /// <summary>
        /// 设置PUCT 解析
        /// </summary>
        /// <param name="blist"></param>
        public static void SetPuct(List<BinBase> blist)
        {
            ///设置是否存咋puct区
            PuctHelp.IsPuct = false;
            //puct
            var tlist1 = blist.Where(c => !string.IsNullOrEmpty(c.note) && c.note.Contains("PU_CT") ).ToList();

            var str = $"{tlist1[3].original.ToString("X2")}{tlist1[2].original.ToString("X2")}{tlist1[1].original.ToString("X2")}{tlist1[0].original.ToString("X2")}";
            if (str != "FFFFFFFF")
            {
                var puctIndex = Convert.ToInt32(str, 16);
                PuctHelp.PuctIndex = puctIndex;
                PuctHelp.IsPuct = true;
                if (IsPrint)
                {
                    using (StreamWriter writer = new StreamWriter($"{System.IO.Directory.GetCurrentDirectory() }\\B_522setting.txt"))
                    {
                        for (int i = 0; i < 0x50; i++)
                        {
                            writer.WriteLine($"0x{i.ToString("X4")},0x{blist[i + puctIndex].original.ToString("X2")} ");
                        }
                    }
                }
               
                for (int i = 0; i < PuctHelp.Parameters.Count(); i++)
                {
                    if (PuctHelp.Parameters[i].Note.Contains("PU_HUE_CONTROL 色调"))
                    {
                        var focus = $"{blist[(i * 2) + puctIndex + 1].original.ToString("X2")}{blist[(i * 2) + puctIndex].original.ToString("X2")}";
                    }

                    if (PuctHelp.Parameters[i].Note.Contains("CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 曝光"))
                    {
                        var focus = $"{blist[(i * 2) + puctIndex + 1].original.ToString("X2")}{blist[(i * 2) + puctIndex].original.ToString("X2")}";

                        PuctHelp.Parameters[i].valL = SetPuct_EXPOSURE_L(focus); 
                        PuctHelp.Parameters[i].valH = SetPuct_EXPOSURE_H(focus);
                    }
                    else
                    {
                        PuctHelp.Parameters[i].valL = $"{blist[(i * 2) + puctIndex].original.ToString("X2")}";
                        PuctHelp.Parameters[i].valH = $"{blist[(i * 2) + puctIndex + 1].original.ToString("X2")}"; 
                    }
                    
                }
               
            
            }

            //0_1setting 文件
            var startHeaderIndex = blist.FindIndex(c => null != c.note && c.note.Contains("setting区0_01_首地址"));
            var endHeaderIndex = blist.FindLastIndex(c => null != c.note && c.note.Contains("Header_crc"));
            var nums = endHeaderIndex - startHeaderIndex;
            var appENList = blist.Where(c => null != c.note && c.note.Contains("App setting区0_01") && c.note.Contains("_en") && c.original == 1).Select(c => c.note.Replace("_en", "")).Distinct().ToList();
            var result = blist.Skip(startHeaderIndex).Take(nums).Where(c => null != c.note && c.sort == 0x3 && appENList.Any(b => c.note.Contains(b))).ToList();

            foreach (var item in result)
            {
                if (item.sort == 0x3)
                {
                    //根据地址  找到地址的起始位置   更具5843151  后面的长度*4 计算需要的长度信息
                    var sdata = Convert.ToInt32(item.smalldata, 16);

                   
                    if (blist.Count <= sdata)
                    {
                        continue;
                    }
                    var t = blist[sdata];
                    var t1 = blist[sdata + 4];
                    int count = 0;
                    if (t.smalladdr == "5843" && t.smalldata == "0151" && t1.smalldata != "0000")
                    {
                        count = Convert.ToInt32(t1.smalldata, 16) * 4;
                    }
                    //添加过滤无效字段，0000这个字段对IQ文件赋值存在影响
                    for (int i = 0; i < 4; i++)
                    {
                        blist[sdata + 4 + i].IsSetting = false;
                    }
                    var sResult = blist.Skip(sdata).Take(count).ToList();
                    
                    PuctHelp.AppSetting0_0StartData = sdata;
                    PuctHelp.AppSetting0_0Count = count;
                    if (IsPrint)
                    {
                        using (StreamWriter writer = new StreamWriter($"{System.IO.Directory.GetCurrentDirectory() }\\B0_01setting.txt"))
                        {
                            for (int i = 0; i < sResult.Count; i++)
                            {
                                if (i + 4 < sResult.Count)
                                {
                                    writer.WriteLine($"{sResult[i + 3].smallexample},{sResult[i + 3].original.ToString("X2")}//{sResult[i + 3].addresspart} --{sResult[i + 3].note} --{sResult[i + 3].remarks}");
                                    writer.WriteLine($"{sResult[i + 2].smallexample},{sResult[i + 2].original.ToString("X2")}//{sResult[i + 2].addresspart} --{sResult[i + 2].note} --{sResult[i + 2].remarks}");
                                    writer.WriteLine($"{sResult[i + 1].smallexample},{sResult[i + 1].original.ToString("X2")}//{sResult[i + 1].addresspart} --{sResult[i + 1].note} --{sResult[i + 1].remarks}");
                                    writer.WriteLine($"{sResult[i].smallexample},{sResult[i].original.ToString("X2")}//{sResult[i].addresspart} --{sResult[i].note} --{sResult[i].remarks}");
                                    i += 3;
                                }

                            }
                        }
                    }
                    
                    ////PID
                    //0x61de,0x84,
                    //0x61df,0x78,
                    ////VID
                    //0x61dc,0x43,
                    //0x61dd,0x58,
                    PuctHelp.userParametersUsb.PidAddrL = sResult.Where(c => c.addrsmallex.ToLower().Contains("61de") && c.AddrVal == AddressValueEnum.Val).ToList();
                    var pidvalL = Convert.ToUInt32($"{PuctHelp.userParametersUsb.PidAddrL.Find(c => c.sort == 1).original.ToString("X2")}{PuctHelp.userParametersUsb.PidAddrL.Find(c => c.sort == 0).original.ToString("X2")}", 16);
                    PuctHelp.userParametersUsb.PidAddrH = sResult.Where(c => c.addrsmallex.ToLower().Contains("61df") && c.AddrVal == AddressValueEnum.Val).ToList();
                    var pidvalH = Convert.ToUInt32($"{PuctHelp.userParametersUsb.PidAddrH.Find(c => c.sort == 1).original.ToString("X2")}{PuctHelp.userParametersUsb.PidAddrH.Find(c => c.sort == 0).original.ToString("X2")}", 16);
                    PuctHelp.userParametersUsb.PidNumber = Convert.ToUInt32($"{pidvalH.ToString("X2")}{pidvalL.ToString("X2")}", 16);

                    PuctHelp.userParametersUsb.VidAddrL = sResult.Where(c => c.addrsmallex.ToLower().Contains("61dc") && c.AddrVal == AddressValueEnum.Val).ToList();
                    var vidvalL = Convert.ToUInt32($"{PuctHelp.userParametersUsb.VidAddrL.Find(c => c.sort == 1).original.ToString("X2")}{PuctHelp.userParametersUsb.VidAddrL.Find(c => c.sort == 0).original.ToString("X2")}", 16);
                    PuctHelp.userParametersUsb.VidAddrH = sResult.Where(c => c.addrsmallex.ToLower().Contains("61dd") && c.AddrVal == AddressValueEnum.Val).ToList();
                    var vidvalH = Convert.ToUInt32($"{PuctHelp.userParametersUsb.VidAddrH.Find(c => c.sort == 1).original.ToString("X2")}{PuctHelp.userParametersUsb.VidAddrH.Find(c => c.sort == 0).original.ToString("X2")}", 16);
                    PuctHelp.userParametersUsb.VidNumber = Convert.ToUInt32($"{vidvalH.ToString("X2")}{vidvalL.ToString("X2")}", 16);

                    //参数设置中 查找最大值最小值默认值，当期值  

                    SetControlProperties(PuctHelp.PU_BRIGHTNESS_CONTROL, sResult, PuctHelp.PU_BRIGHTNESS_CONTROL.max_addr_h, PuctHelp.PU_BRIGHTNESS_CONTROL.max_addr_l, PuctHelp.PU_BRIGHTNESS_CONTROL.min_addr_h, PuctHelp.PU_BRIGHTNESS_CONTROL.min_addr_l, PuctHelp.PU_BRIGHTNESS_CONTROL.def_addr_h, PuctHelp.PU_BRIGHTNESS_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_CONTRAST_CONTROL, sResult, PuctHelp.PU_CONTRAST_CONTROL.max_addr_h, PuctHelp.PU_CONTRAST_CONTROL.max_addr_l, PuctHelp.PU_CONTRAST_CONTROL.min_addr_h, PuctHelp.PU_CONTRAST_CONTROL.min_addr_l, PuctHelp.PU_CONTRAST_CONTROL.def_addr_h, PuctHelp.PU_CONTRAST_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_HUE_CONTROL, sResult, PuctHelp.PU_HUE_CONTROL.max_addr_h, PuctHelp.PU_HUE_CONTROL.max_addr_l, PuctHelp.PU_HUE_CONTROL.min_addr_h, PuctHelp.PU_HUE_CONTROL.min_addr_l, PuctHelp.PU_HUE_CONTROL.def_addr_h, PuctHelp.PU_HUE_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_SATURATION_CONTROL, sResult, PuctHelp.PU_SATURATION_CONTROL.max_addr_h, PuctHelp.PU_SATURATION_CONTROL.max_addr_l, PuctHelp.PU_SATURATION_CONTROL.min_addr_h, PuctHelp.PU_SATURATION_CONTROL.min_addr_l, PuctHelp.PU_SATURATION_CONTROL.def_addr_h, PuctHelp.PU_SATURATION_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_SHARPNESS_CONTROL, sResult, PuctHelp.PU_SHARPNESS_CONTROL.max_addr_h, PuctHelp.PU_SHARPNESS_CONTROL.max_addr_l, PuctHelp.PU_SHARPNESS_CONTROL.min_addr_h, PuctHelp.PU_SHARPNESS_CONTROL.min_addr_l, PuctHelp.PU_SHARPNESS_CONTROL.def_addr_h, PuctHelp.PU_SHARPNESS_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_GAMMA_CONTROL, sResult, PuctHelp.PU_GAMMA_CONTROL.max_addr_h, PuctHelp.PU_GAMMA_CONTROL.max_addr_l, PuctHelp.PU_GAMMA_CONTROL.min_addr_h, PuctHelp.PU_GAMMA_CONTROL.min_addr_l, PuctHelp.PU_GAMMA_CONTROL.def_addr_h, PuctHelp.PU_GAMMA_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_CONTROL, sResult, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_CONTROL.max_addr_h, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_CONTROL.max_addr_l, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_CONTROL.min_addr_h, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_CONTROL.min_addr_l, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_CONTROL.def_addr_h, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_BACKLIGHT_COMPENSATION_CONTROL, sResult, PuctHelp.PU_BACKLIGHT_COMPENSATION_CONTROL.max_addr_h, PuctHelp.PU_BACKLIGHT_COMPENSATION_CONTROL.max_addr_l, PuctHelp.PU_BACKLIGHT_COMPENSATION_CONTROL.min_addr_h, PuctHelp.PU_BACKLIGHT_COMPENSATION_CONTROL.min_addr_l, PuctHelp.PU_BACKLIGHT_COMPENSATION_CONTROL.def_addr_h, PuctHelp.PU_BACKLIGHT_COMPENSATION_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_GAIN_CONTROL, sResult, PuctHelp.PU_GAIN_CONTROL.max_addr_h, PuctHelp.PU_GAIN_CONTROL.max_addr_l, PuctHelp.PU_GAIN_CONTROL.min_addr_h, PuctHelp.PU_GAIN_CONTROL.min_addr_l, PuctHelp.PU_GAIN_CONTROL.def_addr_h, PuctHelp.PU_GAIN_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.CT_FOCUS_ABSOLUTE_CONTROL, sResult, PuctHelp.CT_FOCUS_ABSOLUTE_CONTROL.max_addr_h, PuctHelp.CT_FOCUS_ABSOLUTE_CONTROL.max_addr_l, PuctHelp.CT_FOCUS_ABSOLUTE_CONTROL.min_addr_h, PuctHelp.CT_FOCUS_ABSOLUTE_CONTROL.min_addr_l, PuctHelp.CT_FOCUS_ABSOLUTE_CONTROL.def_addr_h, PuctHelp.CT_FOCUS_ABSOLUTE_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.CT_AE_MODE_CONTROL, sResult, PuctHelp.CT_AE_MODE_CONTROL.max_addr_h, PuctHelp.CT_AE_MODE_CONTROL.max_addr_l, PuctHelp.CT_AE_MODE_CONTROL.min_addr_h, PuctHelp.CT_AE_MODE_CONTROL.min_addr_l, PuctHelp.CT_AE_MODE_CONTROL.def_addr_h, PuctHelp.CT_AE_MODE_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.PU_POWER_LINE_FREQUENCY_CONTROL, sResult, PuctHelp.PU_POWER_LINE_FREQUENCY_CONTROL.max_addr_h, PuctHelp.PU_POWER_LINE_FREQUENCY_CONTROL.max_addr_l, PuctHelp.PU_POWER_LINE_FREQUENCY_CONTROL.min_addr_h, PuctHelp.PU_POWER_LINE_FREQUENCY_CONTROL.min_addr_l, PuctHelp.PU_POWER_LINE_FREQUENCY_CONTROL.def_addr_h, PuctHelp.PU_POWER_LINE_FREQUENCY_CONTROL.def_addr_l);


                    SetControlProperties(PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, sResult, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL.max_addr_h, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL.max_addr_l, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL.min_addr_h, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL.min_addr_l, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL.def_addr_h, PuctHelp.PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.CT_FOCUS_AUTO_CONTROL, sResult, PuctHelp.CT_FOCUS_AUTO_CONTROL.max_addr_h, PuctHelp.CT_FOCUS_AUTO_CONTROL.max_addr_l, PuctHelp.CT_FOCUS_AUTO_CONTROL.min_addr_h, PuctHelp.CT_FOCUS_AUTO_CONTROL.min_addr_l, PuctHelp.CT_FOCUS_AUTO_CONTROL.def_addr_h, PuctHelp.CT_FOCUS_AUTO_CONTROL.def_addr_l);
                    SetControlProperties(PuctHelp.CT_AE_MODE_AUTO_CONTROL, sResult, PuctHelp.CT_AE_MODE_AUTO_CONTROL.max_addr_h, PuctHelp.CT_AE_MODE_AUTO_CONTROL.max_addr_l, PuctHelp.CT_AE_MODE_AUTO_CONTROL.min_addr_h, PuctHelp.CT_AE_MODE_AUTO_CONTROL.min_addr_l, PuctHelp.CT_AE_MODE_AUTO_CONTROL.def_addr_h, PuctHelp.CT_AE_MODE_AUTO_CONTROL.def_addr_l);



                    PuctHelp.userParametersUsb.VideoMicStartIndex = sResult.FindIndex(c => c.addrsmallex.ToLower().Contains("62cc"));
                    PuctHelp.userParametersUsb.VideoMicEndIndex = sResult.FindLastIndex(c => c.addrsmallex.ToLower().Contains("630b"));
                    List<byte> videoMicList = new List<byte>();
                    for (int i = PuctHelp.userParametersUsb.VideoMicStartIndex - 3; i < PuctHelp.userParametersUsb.VideoMicEndIndex + 3; i++)
                    {
                        //需要处理掉fff8 和fff9和F6F5的数据
                        //需要翻转地址
                        if (sResult[i].smallexample.Contains("FFF8") || sResult[i].smallexample.Contains("FFF9") || sResult[i].smallexample.Contains("F6F5")) continue;
                        videoMicList.AddRange(new byte[] { sResult[i + 3].original, sResult[i + 2].original, sResult[i + 1].original, sResult[i].original });
                        i += 3;

                    }
                    PuctHelp.userParametersUsb.VideoMicList = new List<byte>();
                    PuctHelp.userParametersUsb.VideoMicList.AddRange(videoMicList);
                    //去掉bLength  去掉bDescriptorType 
                    videoMicList.RemoveAll(c => c == 0);
                    videoMicList.RemoveRange(0, 2);
                    PuctHelp.userParametersUsb.VideoMicName = Encoding.ASCII.GetString(videoMicList.ToArray());
                    PuctHelp.userParametersUsb.VideoMicStartIndex += sdata;
                    PuctHelp.userParametersUsb.VideoMicEndIndex += sdata;

                    //624c 628b 由于大小端问题  624c需要减3  628b需要加3
                    PuctHelp.userParametersUsb.VideoStartIndex = sResult.FindIndex(c => c.addrsmallex.ToLower().Contains("624c"));
                    PuctHelp.userParametersUsb.VideoEndIndex = sResult.FindLastIndex(c => c.addrsmallex.ToLower().Contains("628b"));

                    List<byte> videoList = new List<byte>();
                    for (int i = PuctHelp.userParametersUsb.VideoStartIndex - 3; i < PuctHelp.userParametersUsb.VideoEndIndex + 3; i++)
                    {
                        //需要处理掉fff8 和fff9和F6F5的数据
                        //需要翻转地址
                        if (sResult[i].smallexample.Contains("FFF8") || sResult[i].smallexample.Contains("FFF9") || sResult[i].smallexample.Contains("F6F5")) continue;
                        videoList.AddRange(new byte[] { sResult[i + 3].original, sResult[i + 2].original, sResult[i + 1].original, sResult[i].original });
                        i += 3;

                    }
                    PuctHelp.userParametersUsb.VideoList = new List<byte>();
                    PuctHelp.userParametersUsb.VideoList.AddRange(videoList);
                    //去掉bLength  去掉bDescriptorType 
                    videoList.RemoveAll(c => c == 0);
                    videoList.RemoveRange(0, 2);
                    PuctHelp.userParametersUsb.VideoName = Encoding.ASCII.GetString((videoList).ToArray());
                    PuctHelp.userParametersUsb.VideoStartIndex += sdata;
                    PuctHelp.userParametersUsb.VideoEndIndex += sdata;


                    PuctHelp.userParametersUsb.ManufactureStartIndex = sResult.FindIndex(c => c.addrsmallex.ToLower().Contains("620c"));
                    PuctHelp.userParametersUsb.ManufactureEndIndex = sResult.FindLastIndex(c => c.addrsmallex.ToLower().Contains("624b"));

                    var ManufactureList = new List<byte>();
                    for (int i = PuctHelp.userParametersUsb.ManufactureStartIndex - 3; i < PuctHelp.userParametersUsb.ManufactureEndIndex + 3; i++)
                    {
                        if (sResult[i].smallexample.Contains("FFF8") || sResult[i].smallexample.Contains("FFF9") || sResult[i].smallexample.Contains("F6F5")) continue;

                        ManufactureList.AddRange(new byte[] { sResult[i + 3].original, sResult[i + 2].original, sResult[i + 1].original, sResult[i].original });
                        i += 3;
                    }
                    PuctHelp.userParametersUsb.ManufactureList = new List<byte>();
                    PuctHelp.userParametersUsb.ManufactureList.AddRange(ManufactureList);
                    //ManufactureList = ManufactureList.Where(c => c != 0).ToList();
                    //ManufactureList.Remove(ManufactureList[0]);
                    //ManufactureList.Remove(ManufactureList[0]);
                    ManufactureList.RemoveAll(c => c == 0);
                    ManufactureList.RemoveRange(0, 2);
                    PuctHelp.userParametersUsb.ManufactureName = Encoding.ASCII.GetString(ManufactureList.ToArray());
                    PuctHelp.userParametersUsb.ManufactureStartIndex += sdata;
                    PuctHelp.userParametersUsb.ManufactureEndIndex += sdata;

                    PuctHelp.userParametersUsb.SerialNumberStartIndex = sResult.FindIndex(c => c.addrsmallex.ToLower().Contains("628c"));
                    PuctHelp.userParametersUsb.SerialNumberEndIndex = sResult.FindLastIndex(c => c.addrsmallex.ToLower().Contains("62cb"));

                    List<byte> SeriaNumberList = new List<byte>();
                    for (int i = PuctHelp.userParametersUsb.SerialNumberStartIndex - 3; i < PuctHelp.userParametersUsb.SerialNumberEndIndex + 3; i++)
                    {
                        if (sResult[i].smallexample.Contains("FFF8") || sResult[i].smallexample.Contains("FFF9") || sResult[i].smallexample.Contains("F6F5")) continue;
                        SeriaNumberList.Add(sResult[i + 3].original);
                        SeriaNumberList.Add(sResult[i + 2].original);
                        SeriaNumberList.Add(sResult[i + 1].original);
                        SeriaNumberList.Add(sResult[i].original);
                        i += 3;

                    }
                    PuctHelp.userParametersUsb.SerialNumberList = new List<byte>();
                    PuctHelp.userParametersUsb.SerialNumberList.AddRange(SeriaNumberList);
                    SeriaNumberList = SeriaNumberList.Where(c => c != 0).ToList();
                    SeriaNumberList.Remove(SeriaNumberList[0]);
                    SeriaNumberList.Remove(SeriaNumberList[0]);
                    PuctHelp.userParametersUsb.SerialNumberName = Encoding.ASCII.GetString(SeriaNumberList.ToArray());
                    PuctHelp.userParametersUsb.SerialNumberStartIndex += sdata;
                    PuctHelp.userParametersUsb.SerialNumberEndIndex += sdata;

                    //Video Control Input Terminal
                    //12 24 02 01 02 01 00 00 00 00 00 00 00 00 03 2A
                    //调换sResult 四个字节的数据 否则无法正确匹配数据，
                    //存在地址和数据位大小端数据不在同一个4个连续地址里面，
                    //会存在变动的情况下无法正确去识别 固需要把吧大小端模式进行转换然后进行识别
                    List<BinBase> tResult = new List<BinBase>();
                    for (int i = 0; i < sResult.Count; i += 4)
                    {
                        if (i + 3 < sResult.Count)
                        {
                            if (sResult[i].smallexample.Contains("FFF8") || sResult[i].smallexample.Contains("FFF9") || sResult[i].smallexample.Contains("F6F5")) continue;
                            tResult.Add(sResult[i + 3]);
                            tResult.Add(sResult[i + 2]);
                            tResult.Add(sResult[i + 1]);
                            tResult.Add(sResult[i + 0]);
                        }
                    }
                    PuctHelp.TResult = new List<BinBase>();
                    PuctHelp.TResult.AddRange(tResult);
                    if (IsPrint)
                    {
                        using (StreamWriter writer = new StreamWriter($"{System.IO.Directory.GetCurrentDirectory() }\\B_描述符setting.txt"))
                        {
                            for (int i = 0; i < tResult.Count; i++)
                            {
                                writer.WriteLine($"0x{tResult[i].addrsmallex},0x{tResult[i].original.ToString("X2")} ");
                            }
                        }
                    }
                   


                    List<uint> videoHeard = new List<uint>() { 0x0f, 0x24, 0x02, 0x01,0x01,0x02 };
                    List<BinBase> videoCIResult = new List<BinBase>();
                    for (int i = 0; i < tResult.Count; i++)
                    {

                        if (i + 3 < tResult.Count
                         && tResult[i + 0].original >= videoHeard[0]
                         && tResult[i + 1].original == videoHeard[1]
                         && tResult[i + 2].original == videoHeard[2]
                         && tResult[i + 3].original == videoHeard[3])
                        {
                            for (int j = 0; j < tResult[i + 0].original; j++)
                            {
                                videoCIResult.Add(tResult[i + j]);
                            }
                        }
                    }
                    PuctHelp.userParametersUsb.VideoCIResult = new List<BinBase>();
                    PuctHelp.userParametersUsb.VideoCIResult.AddRange(videoCIResult);
                    //Video Control Processing Unit
                    //0C 24 05 07 01 00 00 03 7B 17 00 01
                    List<uint> videoCPHeard = new List<uint>() { 0x09, 0x24, 0x05, 0x07,0x01 };
                    List<BinBase> videoCPResult = new List<BinBase>();
                    for (int i = 0; i < tResult.Count; i++)
                    {

                        if (i + 4 < tResult.Count
                         &&  tResult[i + 0].original >= videoCPHeard[0]
                         && tResult[i + 1].original == videoCPHeard[1]
                         && tResult[i + 2].original == videoCPHeard[2]
                         && tResult[i + 3].original == videoCPHeard[3]
                         && tResult[i + 4].original == videoCPHeard[4])
                        {
                            for (int j = 0; j < tResult[i + 0].original; j++)
                            {
                                videoCPResult.Add(tResult[i + j]);
                            }
                        }
                    }
                    PuctHelp.userParametersUsb.VideoCPResult = new List<BinBase>();
                    PuctHelp.userParametersUsb.VideoCPResult.AddRange(videoCPResult);

                    //VC - Specific VS Video Input Header Descriptor
                    //0F 24 01 02 51 03 83 00 02      0E 24 01 01 8B 00 83 00 02
                    List<uint> videoIHDHeard = new List<uint>() { 0x0F, 0x24, 0x01, 0x02, 0x51, 0x03, 0x83, 0x00, 0x02 };
                    List<BinBase> videoIHDResult = new List<BinBase>();
                    for (int i = 0; i < tResult.Count; i++)
                    {

                        if (i + 9 < tResult.Count
                         
                         && tResult[i + 1].original == videoIHDHeard[1]
                         && tResult[i + 2].original == videoIHDHeard[2]
                         && tResult[i + 6].original == videoIHDHeard[6]
                         && tResult[i + 7].original == videoIHDHeard[7]
                         && tResult[i + 8].original == videoIHDHeard[8])
                        {
                            for (int j = 0; j < tResult[i + 0].original; j++)
                            {
                                videoIHDResult.Add(tResult[i + j]);
                            }
                        }
                    }
                    PuctHelp.VideoIHDResult = new List<BinBase>();
                    PuctHelp.VideoIHDResult.AddRange(videoIHDResult);
                    //解析需要的参数
                    if (PuctHelp.VideoIHDResult.Count>0)
                    {
                        PuctHelp.videoIHDNum = PuctHelp.VideoIHDResult[3].original;
                        PuctHelp.videoIHDTotal = Convert.ToInt32($"{PuctHelp.VideoIHDResult[5].original.ToString("X2")}{PuctHelp.VideoIHDResult[4].original.ToString("X2")}",16);
                        PuctHelp.videoIHDStillCapture = PuctHelp.VideoIHDResult[9].original;
                    }
                   


                    //Video Streaming MJPEG Format Type Descriptor 
                    //0B 24 06 01 11 00 07 00
                    List<uint> videoSFormatMjpegHeard = new List<uint>() { 0x0B, 0x24, 0x06 };
                    List<BinBase> videoSFormatMjpegResult = new List<BinBase>();
                    for (int i = 0; i < tResult.Count; i++)
                    {

                        if (i + 2 < tResult.Count
                         &&  tResult[i + 0].original == videoSFormatMjpegHeard[0]
                         && tResult[i + 1].original == videoSFormatMjpegHeard[1]
                         && tResult[i + 2].original == videoSFormatMjpegHeard[2])
                        {
                            for (int j = 0; j < 0x0B; j++)
                            {
                                videoSFormatMjpegResult.Add(tResult[i + j]);
                            }
                            //PuctHelp.MjpegbFormatIndex = tResult[i + 3].original;
                        }
                    }
                    PuctHelp.VideoSFormatMjpegResult = new List<BinBase>();
                    PuctHelp.VideoSFormatMjpegResult.AddRange(videoSFormatMjpegResult);
                    //解析需要的参数
                    if (PuctHelp.VideoSFormatMjpegResult.Count == 0x0B)
                    {
                        PuctHelp.videoSFormatMjpegIndex = PuctHelp.VideoSFormatMjpegResult[3].original;
                        PuctHelp.videoSFormatMjpegNum = PuctHelp.VideoSFormatMjpegResult[4].original;
                        PuctHelp.videoSFormatMjpegDefaultIndex = PuctHelp.VideoSFormatMjpegResult[6].original;
                    }
                   
                    PuctHelp.VideoMjpegFTypes = new List<VideoMjpegFType>();
                    for (int j = 0; j < PuctHelp.videoSFormatMjpegNum; j++)
                    {
                        List<uint> videoSMjpegFTypeHeard = new List<uint>() { 0x1e, 0x24, 0x07, (uint)j + 0x1 };
                        List<BinBase> videoSMjpegFTypeResult = new List<BinBase>();
                        for (int i = 0; i < tResult.Count; i++)
                        {

                            if (i + 3 < tResult.Count
                             &&   tResult[i + 0].original >= videoSMjpegFTypeHeard[0]
                             && tResult[i + 1].original == videoSMjpegFTypeHeard[1]
                             && tResult[i + 2].original == videoSMjpegFTypeHeard[2]
                             && tResult[i + 3].original == videoSMjpegFTypeHeard[3])
                            {
                                    for (int z = 0; z < tResult[i + 0].original; z++)
                                    {
                                        videoSMjpegFTypeResult.Add(tResult[i + z]);
                                    }
                                
                            }
                        }
                        VideoMjpegFType videoMjpegF = new VideoMjpegFType();
                        videoMjpegF.VideoSMjpegFTypeResult = new List<BinBase>();
                        videoMjpegF.VideoSMjpegFTypeResult.AddRange(videoSMjpegFTypeResult);
                        if (videoSMjpegFTypeResult.Count>0)
                        {
                            videoMjpegF.videoSMjpegFTypeIndex = videoSMjpegFTypeResult[3].original;
                            videoMjpegF.videoSMjpegFTypeWidth = Convert.ToInt32($"{videoSMjpegFTypeResult[6].original.ToString("X2")}{videoSMjpegFTypeResult[5].original.ToString("X2")}", 16);
                            videoMjpegF.videoSMjpegFTypeHeight = Convert.ToInt32($"{videoSMjpegFTypeResult[8].original.ToString("X2")}{videoSMjpegFTypeResult[7].original.ToString("X2")}", 16);

                        }

                        PuctHelp.VideoMjpegFTypes.Add(videoMjpegF);

                    }


                    //VS Uncompressed Format Type Descriptor 
                    //1B 24 04 02 06 59 55 59 
                    List<uint> videoSFormatYuvHeard = new List<uint>() { 0x1B, 0x24, 0x04 };
                    List<BinBase> videoSFormatYuvResult = new List<BinBase>();
                    for (int i = 0; i < tResult.Count; i++)
                    {

                        if (i + 2 < tResult.Count
                         &&   tResult[i + 0].original == videoSFormatYuvHeard[0]
                         && tResult[i + 1].original == videoSFormatYuvHeard[1]
                         && tResult[i + 2].original == videoSFormatYuvHeard[2])
                        {
                            for (int j = 0; j < 0x1B; j++)
                            {
                                videoSFormatYuvResult.Add(tResult[i + j]);
                            }
                            //PuctHelp.YuvbFormatIndex = tResult[i + 3].original;
                        }
                    }
                    PuctHelp.VideoSFormatYuvResult = new List<BinBase>();
                    PuctHelp.VideoSFormatYuvResult.AddRange(videoSFormatYuvResult);
                    if (PuctHelp.VideoSFormatYuvResult.Count == 0x1B)
                    {
                        PuctHelp.videoSFormatYuvIndex = PuctHelp.VideoSFormatYuvResult[3].original;
                        PuctHelp.videoSFormatYuvNum = PuctHelp.VideoSFormatYuvResult[4].original;
                        PuctHelp.videoSFormatYuvDefaultIndex = PuctHelp.VideoSFormatYuvResult[22].original;
                    }
                   
                    PuctHelp.VideoYuvFTypes = new List<VideoYuvFType>();
                    for (int j = 0; j < PuctHelp.videoSFormatYuvNum; j++)
                    {
                        //1E 24 05 01 00 00
                        List<uint> videoSYuvFTypeHeard = new List<uint>() { 0x1e, 0x24, 0x05, (uint)j + 0x1 };
                        List<BinBase> videoSYuvFTypeResult = new List<BinBase>();
                        for (int i = 0; i < tResult.Count; i++)
                        {

                            if (
                                i+3 < tResult.Count
                             && tResult[i + 0].original >= videoSYuvFTypeHeard[0]
                             && tResult[i + 1].original == videoSYuvFTypeHeard[1]
                             && tResult[i + 2].original == videoSYuvFTypeHeard[2]
                             && tResult[i + 3].original == videoSYuvFTypeHeard[3])
                            {
                               
                                    for (int z = 0; z < tResult[i + 0].original; z++)
                                    {
                                        videoSYuvFTypeResult.Add(tResult[i + z]);
                                    }
                               
                                
                            }
                        }
                        VideoYuvFType videoYuvF = new VideoYuvFType();
                        videoYuvF.VideoSYuvFTypeResult = new List<BinBase>();
                        videoYuvF.VideoSYuvFTypeResult.AddRange(videoSYuvFTypeResult);
                        if (videoSYuvFTypeResult.Count>0)
                        {
                            videoYuvF.videoSYuvFTypeIndex = videoSYuvFTypeResult[3].original;
                            videoYuvF.videoSYuvFTypeWidth = Convert.ToInt32($"{videoSYuvFTypeResult[6].original.ToString("X2")}{videoSYuvFTypeResult[5].original.ToString("X2")}", 16);
                            videoYuvF.videoSYuvFTypeHeight = Convert.ToInt32($"{videoSYuvFTypeResult[8].original.ToString("X2")}{videoSYuvFTypeResult[7].original.ToString("X2")}", 16);

                        }

                        PuctHelp.VideoYuvFTypes.Add(videoYuvF);
                    }

                    //Still Image Frame Type Descriptor -----
                    //3A 24 03 00 0D 00 12 80
                    List<uint> stillImageFrameTypeHeard = new List<uint>() { 0x00, 0x24, 0x03, 0x00 };
                    PuctHelp.StillImageFrameTypeResultOne = new List<BinBase>();
                    PuctHelp.StillImageFrameTypeResultTwo = new List<BinBase>();

                    bool isFirstTime = true;
                    for (int i = 0; i < tResult.Count - 3; i++)
                    {
                        if (tResult[i + 1].original == stillImageFrameTypeHeard[1]
                            && tResult[i + 2].original == stillImageFrameTypeHeard[2]
                            && tResult[i + 3].original == stillImageFrameTypeHeard[3])
                        {
                            if (isFirstTime)
                            {
                                for (int j = 0; j < tResult[i].original; j++)
                                {
                                    PuctHelp.StillImageFrameTypeResultOne.Add(tResult[i + j]);
                                }
                                isFirstTime = false;
                            }
                            else
                            {
                                for (int j = 0; j < tResult[i].original; j++)
                                {
                                    PuctHelp.StillImageFrameTypeResultTwo.Add(tResult[i + j]);
                                }
                                break; // 第二次进来后直接退出循环
                            }
                        }
                    }

                    //PuctHelp.StillImageFrameTypeResult.AddRange(stillImageFrameTypeResult);

                    //Configuration Descriptor  -----
                    //09 02 A4 05 04 01 00 80 80 08 0B 00 02 0E 03 00
                    List<uint> configDesTypeHeard = new List<uint>() { 0x09, 0x02, 0x0, 0x0, 0x4, 0x1, 0x0, 0x80, 0x80 };
                    List<uint> configeHeard = new List<uint>() { 0x08, 0x0b, 0x02, 0x02, 0x01, 0x02 };
                    int bLength = CalculateBLength(tResult, configeHeard);
                    List<BinBase> configDesTypeResult = new List<BinBase>();
                    for (int i = 0; i < tResult.Count; i++)
                    {
                        if (i + 9 < tResult.Count
                            && tResult[i + 0].original == configDesTypeHeard[0]
                            && tResult[i + 1].original == configDesTypeHeard[1]
                            && tResult[i + 5].original == configDesTypeHeard[5]
                            && tResult[i + 6].original == configDesTypeHeard[6]
                            && tResult[i + 7].original == configDesTypeHeard[7]
                            && tResult[i + 8].original == configDesTypeHeard[8]
                            )
                        {
                            var wTotalLen = Convert.ToUInt16($"{tResult[i + 3].original.ToString("X2")}{tResult[i + 2].original.ToString("X2")}", 16);
                            if (tResult[i + 4].original == 0x2 && bLength >0)
                            {
                                wTotalLen += Convert.ToUInt16( bLength);
                            }
                            for (int j = 0; j < wTotalLen; j++)
                            {
                                configDesTypeResult.Add(tResult[i + j]);
                            }
                        }
                    }
                    PuctHelp.ConfigurationDescriptorResult = new List<BinBase>();
                    PuctHelp.ConfigurationDescriptorResult.AddRange(configDesTypeResult);


                    List<uint> VSColorType = new List<uint>() { 0x06, 0x24, 0x0D, 0x1, 0x1, 0x4};
                    List<BinBase> VSColorTypeResult = new List<BinBase>();
                    for (int i = 0; i < tResult.Count; i++)
                    {
                        if (i + 5 < tResult.Count
                            && tResult[i + 0].original == VSColorType[0]
                            && tResult[i + 1].original == VSColorType[1]
                            && tResult[i + 2].original == VSColorType[2]
                            && tResult[i + 3].original == VSColorType[3]
                            && tResult[i + 4].original == VSColorType[4]
                            && tResult[i + 5].original == VSColorType[5]
                            )
                        {
                            
                            for (int j = 0; j < 6; j++)
                            {
                                VSColorTypeResult.Add(tResult[i + j]);
                            }
                        }
                    }
                    PuctHelp.VsColorMatchingDescriptorDescriptor = new List<BinBase>();
                    PuctHelp.VsColorMatchingDescriptorDescriptor.AddRange(VSColorTypeResult);

                    //PuctHelp.TotalDescription = new List<BinBase>();
                    //PuctHelp.BNumInterfaces = new List<BinBase>();
                    //for (int i = 0; i < tResult.Count; i++)
                    //{
                    //    if (tResult[i].addrsmallex.ToLower().Contains("5ad4"))
                    //    {

                    //        List<byte> temp = new List<byte>();
                    //        var Length = Convert.ToInt32($"{tResult[i + 3].original.ToString("X2")}{tResult[i + 2].original.ToString("X2")}",16);
                    //        for (int z = 0; z < Length; z++)
                    //        {
                    //            PuctHelp.TotalDescription.Add(tResult[i + z]);
                    //        }
                    //    }
                    //    if (tResult[i].addrsmallex.ToLower().Contains("5ad8"))
                    //    {
                    //        PuctHelp.BNumInterfaces.Add(tResult[i]);
                    //    }

                    //}

                }
            }


            // 补丁文件 boot patch
            var patchResult = blist.Where(c => null != c.note && c.note.Contains("boot patch区_FLASH起始地址")).ToList();
            if (IsPrint)
            {
               
                using (StreamWriter writer = new StreamWriter($"{System.IO.Directory.GetCurrentDirectory() }\\Bboot_patch.txt"))
                {
                    for (int i = 0; i < patchResult.Count; i++)
                    {
                        if (i + 4 < patchResult.Count)
                        {
                            writer.WriteLine($"{patchResult[i + 3].smallexample},{patchResult[i + 3].original.ToString("X2")}//{patchResult[i + 3].addresspart} --{patchResult[i + 3].note} --{patchResult[i + 3].remarks}");
                            writer.WriteLine($"{patchResult[i + 2].smallexample},{patchResult[i + 2].original.ToString("X2")}//{patchResult[i + 2].addresspart} --{patchResult[i + 2].note} --{patchResult[i + 2].remarks}");
                            writer.WriteLine($"{patchResult[i + 1].smallexample},{patchResult[i + 1].original.ToString("X2")}//{patchResult[i + 1].addresspart} --{patchResult[i + 1].note} --{patchResult[i + 1].remarks}");
                            writer.WriteLine($"{patchResult[i].smallexample},{patchResult[i].original.ToString("X2")}//{patchResult[i].addresspart} --{patchResult[i].note} --{patchResult[i].remarks}");
                            i += 3;
                        }

                    }
                }
            }
            

            List<byte> patchList = new List<byte>();
            for (int i = 0; i < patchResult.Count; i++)
            {
                //需要处理掉fff8 和fff9和F6F5的数据
                //需要翻转地址
                if (patchResult[i].smallexample.Contains("FFF8") || patchResult[i].smallexample.Contains("FFF9") || patchResult[i].smallexample.Contains("F6F5")) continue;
                //patchList.AddRange(new byte[] { patchResult[i + 3].original, patchResult[i + 2].original, patchResult[i + 1].original, patchResult[i].original });
                patchList.AddRange(new byte[] { patchResult[i].original, patchResult[i + 1].original, patchResult[i + 2].original, patchResult[i + 3].original });
                i += 3;
            }
            PuctHelp.userParametersUsb.UserVerList = new List<byte>();
            PuctHelp.userParametersUsb.UserVerList.AddRange(patchList);
            //查找56 5f 5f 5f 5f
            for (int i = 0; i < patchList.Count; i++)
            {
                if (patchList[i] == 0x56)
                {
                    bool isValidPattern = true;
                    for (int j = i + 1; j <= i + 4; j++)
                    {
                        if (patchList[j] == 0x00)
                        {
                            isValidPattern = false;
                            break;
                        }
                    }
                    if (isValidPattern)
                    {
                        var innerPatternNo = 0;
                        for (int j = i; j <= (patchList.Count - i) + i; j++)
                        {
                            if (patchList[j] == 0x00)
                            {
                                break;
                            }
                            if (patchList[j] == 0x5F)
                            {
                                innerPatternNo++;
                            }
                        }

                        if (innerPatternNo > 3)
                        {
                            Console.WriteLine("Pattern found starting at index: " + i);
                            List<byte> gujianName = new List<byte>();
                            for (int z = i; z < patchList.Count(); z++)
                            {
                                if (patchList[z] == 0x00)
                                {
                                    break;
                                }
                                gujianName.Add(patchList[z]);
                            }
                            //string result1 = Encoding.Default.GetString(gujianName.ToArray());
                            PuctHelp.userParametersUsb.UserVerName = Encoding.Default.GetString(gujianName.ToArray());
                        }
                    }
                }
            }






        }

        public static int CalculateBLength(List<BinBase> data, List<uint> configHeader)
        {
            int bLength = 0;

            for (int i = 0; i < data.Count - 5; i++)
            {
                bool isMatch = true;
                for (int j = 0; j < configHeader.Count; j++)
                {
                    if (data[i + j].original != configHeader[j])
                    {
                        isMatch = false;
                        break;
                    }
                }

                if (isMatch)
                {
                    uint startAddr = Convert.ToUInt32(data[i].smalladdr, 16);
                    for (uint j = startAddr; j < 0x60d3;)
                    {
                        if (i < data.Count)
                        {
                            if (data[i].addrsmallex.ToLower().Contains(j.ToString("x")))
                            {
                                bLength += data[i].original;
                                j += Convert.ToUInt32(data[i].original);
                            }
                            i++;
                        }
                        if (i == data.Count)
                        {
                            break;
                        }
                    }
                }
            }

            return bLength;
        }




        public static void GetTotalDescription(List<BinBase> binBases)
        {
            var sResult = binBases.Skip(PuctHelp.AppSetting0_0StartData).Take(PuctHelp.AppSetting0_0Count).ToList();
            List<BinBase> tResult = new List<BinBase>();
            for (int i = 0; i < sResult.Count; i += 4)
            {
                if (i + 3 < sResult.Count)
                {
                    if (sResult[i].smallexample.Contains("FFF8") || sResult[i].smallexample.Contains("FFF9") || sResult[i].smallexample.Contains("F6F5")) continue;
                    tResult.Add(sResult[i + 3]);
                    tResult.Add(sResult[i + 2]);
                    tResult.Add(sResult[i + 1]);
                    tResult.Add(sResult[i + 0]);
                }
            }
            PuctHelp.TotalDescription = new List<BinBase>();
            PuctHelp.BNumInterfaces = new List<BinBase>();
            for (int i = 0; i < tResult.Count; i++)
            {
                if (tResult[i].addrsmallex.ToLower().Contains("5ad4"))
                {

                    List<byte> temp = new List<byte>();
                    var Length = Convert.ToInt32($"{tResult[i + 3].original.ToString("X2")}{tResult[i + 2].original.ToString("X2")}", 16);
                    for (int z = 0; z < Length; z++)
                    {
                        PuctHelp.TotalDescription.Add(tResult[i + z]);
                    }
                }
                if (tResult[i].addrsmallex.ToLower().Contains("5ad8"))
                {
                    PuctHelp.BNumInterfaces.Add(tResult[i]);
                }

            }

        }


       static  void SetControlProperties(PuctModel controlProperty, List<BinBase> sResult, string maxH, string maxL, string minH, string minL, string defH, string defL)
        {
            controlProperty.max_bool = sResult.Exists(c => c.addrsmallex.ToLower().Contains(maxH) || c.addrsmallex.ToLower().Contains(maxL));
            controlProperty.min_bool = sResult.Exists(c => c.addrsmallex.ToLower().Contains(minH) || c.addrsmallex.ToLower().Contains(minL));
            controlProperty.def_bool = sResult.Exists(c => c.addrsmallex.ToLower().Contains(defH) || c.addrsmallex.ToLower().Contains(defL));
            if (controlProperty.def_bool)
            {
                if (controlProperty.name.Contains("曝光"))
                {
                    var defNo = "";
                    var defHList = sResult.Where(c => c.addrsmallex.ToLower().Contains(defH) && c.AddrVal == AddressValueEnum.Val).ToList();
                    if (defHList.Count >= 2)
                    {
                        defNo = $"{defHList[0].original.ToString("X2")}";
                    }
                    var defLList = sResult.Where(c => c.addrsmallex.ToLower().Contains(defL) && c.AddrVal == AddressValueEnum.Val).ToList();
                    if (defLList.Count >= 2)
                    {
                        defNo += $"{defLList[0].original.ToString("X2")}";
                    }
                    controlProperty.def_val = $"{SetPuct_EXPOSURE_H(defNo)}{SetPuct_EXPOSURE_L(defNo)}";
                }
                else
                {
                    var defNo = "";
                    var defHList = sResult.Where(c => c.addrsmallex.ToLower().Contains(defH) && c.AddrVal == AddressValueEnum.Val).ToList();
                    if (defHList.Count >= 2)
                    {
                        defNo =Convert.ToUInt32( $"{defHList[1].original.ToString("X2")}{defHList[0].original.ToString("X2")}",16).ToString("X2");
                    }
                    var defLList = sResult.Where(c => c.addrsmallex.ToLower().Contains(defL) && c.AddrVal == AddressValueEnum.Val).ToList();
                    if (defLList.Count >= 2)
                    {
                        defNo +=Convert.ToUInt32( $"{defLList[1].original.ToString("X2")}{defLList[0].original.ToString("X2")}",16).ToString("X2");
                    }
                    controlProperty.def_val = defNo;
                }

                
            }
        }

        public static string SetPuct_EXPOSURE_H(string Addr)
        {
            string hex_H = "00";
            switch (Addr)
            {
             
                case "2710":
                    hex_H = "00";
                    break;
                default:
                    hex_H = "FFFFFFFF";
                    break;
            }
            return hex_H;
        }
        public static string SetPuct_EXPOSURE_L(string Addr)
        {
           var tempUint = Convert.ToUInt32(Addr, 16);
            string hex_L = "00";
            switch (tempUint)
            {
                case 0x1:
                    hex_L = "FFFFFFF3";
                    break;
                case 0x2:
                    hex_L = "FFFFFFF4";
                    break;
                case 0x5:
                    hex_L = "FFFFFFF5";
                    break;
                case 0xa:
                    hex_L = "FFFFFFF6";
                    break;
                case 0x14:
                    hex_L = "FFFFFFF7";
                    break;
                case 0x27:
                    hex_L = "FFFFFFF8";
                    break;
                case 0x4e:
                    hex_L = "FFFFFFF9";
                    break;
                case 0x9c:
                    hex_L = "FFFFFFFA";
                    break;
                case 0x138:
                    hex_L = "FFFFFFFB";
                    break;
                case 0x271:
                    hex_L = "FFFFFFFC";
                    break;
                case 0x4e2:
                    hex_L = "FFFFFFFD";
                    break;
                case 0x9c4:
                    hex_L = "FFFFFFFE";
                    break;
                case 0x1388:
                    hex_L = "FFFFFFFF";
                    break;
                case 0x2710:
                    hex_L = "00";
                    break;
                default:
                    break;
            }
            return hex_L;

        }
        public static int GetPuct_EXPOSURE( string  val)
        {
            int hex_L = 0;
            switch (val.ToUpper())
            {
                case "FFF3":
                    hex_L = 0x0001;
                    break;
                case "FFF4":
                    hex_L = 0x0002;
                    break;
                case "FFF5":
                    hex_L = 0x0005;
                    break;
                case "FFF6":
                    hex_L = 0x000a;
                    break;
                case "FFF7":
                    hex_L = 0x0014;
                    break;
                case "FFF8":
                    hex_L = 0x0027;
                    break;
                case "FFF9":
                    hex_L = 0x004e;
                    break;
                case "FFFA":
                    hex_L = 0x009c;
                    break;
                case "FFFB":
                    hex_L = 0x0138;
                    break;
                case "FFFC":
                    hex_L = 0x0271;
                    break;
                case "FFFD":
                    hex_L = 0x04e2;
                    break;
                case "FFFE":
                    hex_L = 0x09c4;
                    break;
                case "FFFF":
                    hex_L = 0x1388;
                    break;
                case "00":
                case "2710":
                    hex_L = 0x2710;
                    break;
                default:
                    break;
            }
            return hex_L;
        }
    }
}
